%% ex1.m
% set dir: src/
close all;
clear; clc;

%% test function
img = imread("../data/lunar_surface.tif");
Fimg = fft2(img);
f = idft2D(Fimg);
figure;
subplot(1,2,1);
imshow(fftshift(log(abs(Fimg)+1)),[]);
title('Spectrogram');
axis off;
subplot(1,2,2);
imshow(real(f),[0,255]);
axis off;
title('Inverse Fourier Transform')
%% idft2D
function f = idft2D(F)
[m, n] = size(F);
f = zeros(m, n);
for i=1:m
    f(i, :) = ifft(F(i,:));
end
for j=1:n
    f(:, j) = ifft(f(:, j));
end
end